package com.wmlive.hhvideo.heihei.mainhome.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wmlive.hhvideo.common.navigator.Navigator;
import com.wmlive.hhvideo.heihei.beans.main.Comment;
import com.wmlive.hhvideo.heihei.login.AccountUtil;
import com.wmlive.hhvideo.utils.imageloader.GlideLoader;
import com.wmlive.hhvideo.widget.refreshrecycler.BaseRecyclerViewHolder;
import com.wmlive.hhvideo.widget.refreshrecycler.RefreshAdapter;
import com.wmlive.hhvideo.widget.refreshrecycler.RefreshRecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.wmlive.hhvideo.R;

/**
 * Created by vhawk on 2017/5/31.
 */

public class VideoCommentAdapter extends RefreshAdapter<VideoCommentAdapter.CommentViewHolder, Comment> {


    public VideoCommentAdapter(List<Comment> list, RefreshRecyclerView refreshView) {
        super(list, refreshView);
    }

    @Override
    public CommentViewHolder onCreateHolder(ViewGroup parent, int viewType) {

        return new CommentViewHolder(parent, R.layout.item_video_comment);
    }

    @Override
    public void onBindHolder(CommentViewHolder holder, int position, Comment data) {
        if (data != null) {

            if (!TextUtils.isEmpty(data.getTitle())) {
                holder.tvCommentContent.setText(data.getTitle());
            }
            if (!TextUtils.isEmpty(data.getUser().getName())) {
                holder.tvUserName.setText(data.getUser().getName());
            }
            if (data.getUser() != null) {
                GlideLoader.loadCircleImage(data.getUser().getCover_url(), holder.ivProfile, R.drawable.find_bg_user_default);
            }
        }

    }

    public void addFirst(Comment comment) {
        mDataContainer.add(0, comment);
        notifyDataSetChanged();
    }

    public class CommentViewHolder extends BaseRecyclerViewHolder {

        @BindView(R.id.ivAvatar)
        ImageView ivProfile;
        @BindView(R.id.tvName)
        TextView tvUserName;
        TextView tvCommentContent;
        private Context context;

        public CommentViewHolder(ViewGroup parent, int layoutId) {
            super(parent, layoutId);
            context = parent.getContext();
        }


        @OnClick(R.id.ivAvatar)
        public void onProfileClick() {
            navigateToUserPage();
        }

        private void navigateToUserPage() {
            Comment comment = getItemData(getLayoutPosition());
            Navigator.getInstance().navigateToOtherUserHome(context, true, comment.getUser_id());
        }

        @OnClick(R.id.tvName)
        public void onUserNameClick() {
            navigateToUserPage();
        }

    }
}
